package com.sky.controller.admin;

import com.github.pagehelper.PageHelper;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("套餐相关接口")
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
  /*
  新增套餐
   */
    @PostMapping("")
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealVO setmealVO) {
        log.info("新增套餐{}",setmealVO);
        setmealService.addSetmeal(setmealVO);
    return Result.success()   ;
    }
//    @ApiOperation("根据ID查询套餐")
//    @GetMapping("/{id}")
//    public Result getSetmeal(@PathVariable Long id) {
//        log.info("根据套餐ID查询菜品");
//        //setmealService.getById(id);
//        return null;
//    }
@GetMapping("/page")
@ApiOperation("分页查询")
public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
    PageResult pageResult = setmealService.selectPage(setmealPageQueryDTO);
    return Result.success(pageResult);
}
    @ApiOperation("套餐起售，停售")
    @PostMapping("/status/{status}")
    public Result setStatus(@PathVariable Long status, Long id) {
        setmealService.setStatus(status,id);
    return  Result.success();
    }
        @ApiOperation("批量删除")
    @DeleteMapping("")
    public Result delete(@RequestParam  List<Long> ids){
        setmealService.deleteSetmeals(ids);
        return Result.success();
        }
    @GetMapping("/{id}")
    @ApiOperation("根据套餐查询ID")
    public Result seleteById(@PathVariable Long id)
    {
        SetmealDTO setmealDTO = setmealService.seleteById(id) ;
        return Result.success(setmealDTO);
    }
    @ApiOperation("套餐修改功能")
    @PutMapping("")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.updateSetmeal(setmealDTO);
        return  Result.success();
    }
}
